<template>
  <!-- 承租方联系人 -->
  <div>
    <el-input
      :placeholder="$t('请输入承租方联系人')"
      :disabled="readonly"
      @change="changeData"
      v-model="checkedData"
      maxlength="8"
      show-word-limit
    ></el-input>
  </div>
</template>
<script>
import nonStandardService from '@/services/nonStandardService'
import eventBus from '@/assets/utils/eventBus.js'
export default {
  name: 'renterContacts',
  props: {
    detail: {
      type: Object,
      default: () => {
        return {}
      },
    },
    value: [Object, String],
    disabled: Boolean,
    parameter: {
      type: Object,
      default: () => {
        return {}
      },
    },
    data: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      checkedData: '',
      readonly: false,
    }
  },
  created() {
    this.readonly = Boolean(this.$route.query.readonly)
    if (this.value) {
      this.setData()
    }
    eventBus.$on('masterChange', (parameter, data) => {
      // 客户
      if (parameter.parameterNumber === 'signTarget') {
        let contactInfos = data.contactInfos || []
        let info =
          contactInfos.find((item) => item.defaultFlag === 1) ||
          contactInfos[0] ||
          {}
        this.checkedData = info.name
        if (this.checkedDat) {
          this.$emit('input', String(this.checkedData))
        }
      }
    })
  },
  methods: {
    changeData() {
      this.$emit('input', String(this.checkedData))
    },
    setData() {
      this.checkedData = JSON.parse(this.value).value
        ? JSON.parse(this.value).value
        : ''
    },
    getData() {
      return {
        value: this.checkedData,
      }
    },
  },
}
</script>
